package com.zxl.openapi.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.stereotype.Component;
import sun.security.action.PutAllAction;

import javax.servlet.http.HttpServletRequest;

import java.util.Map;

import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_TYPE;

/**
 * 单独写这个过滤器的原因是其他过滤器不是每个请求都能用到
 */
@Component
public class LogPreFilter extends ZuulFilter {

    @Override
    public String filterType() {
        return PRE_TYPE;
    }

    @Override
    public int filterOrder() {

        return -200;

    }

    @Override
    public boolean shouldFilter() {

        return true;

    }

    @Override
    public Object run() throws ZuulException {
        //收到请求的时间
        long currentTimeMillis = System.currentTimeMillis();
//        上以下数据在最终的过滤器中都可以获取到
        RequestContext currentContext = RequestContext.getCurrentContext();
//
//        HttpServletRequest request = currentContext.getRequest();
//
//        Map<String, String[]> parameterMap = request.getParameterMap();
//
//        String remoteAddr = request.getRemoteAddr();

        currentContext.put("receiveTime",currentTimeMillis);

        return null;

    }
}
